package com.mscenter.model;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Value;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 应用信息
 * 
 * @author shuibaoqin
 *
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApplicationInfo {
	/**
	 * 应用名
	 */
	private String applicationName;
	/**
	 * 应用描述
	 */
	private String description;
	/**
	 * 基于网关访问的swagger地址
	 */
	private String zuulSwaggerUrl;
	/**
	 * 微服务当前所处环境应
	 */
	private String repoConfig;

	/**
	 * 应用名下的相关实例信息
	 */
	private Set<ApplicationInstanceInfo> applicationInstances;

	/**
	 * 服务端口号
	 */
	private String serverPort;

	/**
	 * 当前环境dev，test，local
	 */
	private String currentEnvProfile;

	/**
	 * 成功运行实例的ip:port
	 */
	private String runtimeConfig;
	
	
	/**
	 * 排序字段
	 */
	private String sortField;
	
	public String getSortField() {
		return sortField;
	}

	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public String getRuntimeConfig() {
		return runtimeConfig;
	}

	public void setRuntimeConfig(String runtimeConfig) {
		this.runtimeConfig = runtimeConfig;
	}

	public String getCurrentEnvProfile() {
		return currentEnvProfile;
	}

	public void setCurrentEnvProfile(String currentEnvProfile) {
		this.currentEnvProfile = currentEnvProfile;
	}

	public String getServerPort() {
		return serverPort;
	}

	public void setServerPort(String serverPort) {
		this.serverPort = serverPort;
	}

	public String getApplicationName() {
		return applicationName;
	}

	public void setApplicationName(String applicationName) {
		this.applicationName = applicationName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getZuulSwaggerUrl() {
		return zuulSwaggerUrl;
	}

	public void setZuulSwaggerUrl(String zuulSwaggerUrl) {
		this.zuulSwaggerUrl = zuulSwaggerUrl;
	}

	public String getRepoConfig() {
		return repoConfig;
	}

	public void setRepoConfig(String repoConfig) {
		this.repoConfig = repoConfig;
	}

	public Set<ApplicationInstanceInfo> getApplicationInstances() {
		return applicationInstances;
	}

	public void setApplicationInstances(Set<ApplicationInstanceInfo> applicationInstances) {
		this.applicationInstances = applicationInstances;
	}

	/**
	 * 将一个实例信息添加到对应的应用下
	 * 
	 * @param appInstanceInfo
	 * @return
	 */
	public boolean addAppInstanceInfo(ApplicationInstanceInfo appInstanceInfo) {
		if (appInstanceInfo == null) {
			return false;
		}
		if (applicationInstances == null) {
			applicationInstances = new HashSet<>();
		}
		return applicationInstances.add(appInstanceInfo);
	}
}